package net.kts.subskill;

import java.util.concurrent.TimeUnit;

import net.kts.attraction.subway.SubwaySearchMap;
import net.kts.main.R;
import net.kts.subskill.airport.AirportGuideMain;
import net.kts.subskill.alarm.Alarm;
import net.kts.subskill.conversation.SubskillConversation;
import net.kts.subskill.tel.Call;
import net.kts.subskill.toilet.ToiletSearch;
import net.kts.transrate.TranslateService;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.Toast;

public class SubSkill extends Activity {

	Button toiletBtn = null;
	private Animation loadAnimation;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.subskill_main);
		loadAnimation = AnimationUtils.loadAnimation(this, R.anim.button_click);
		
		// 공항지도
		Button btnAriport = (Button)findViewById(R.id.btn_subskill_airport);
		// 긴급전화
		Button btnTel = (Button) findViewById(R.id.btn_subskill_tel);
		// 알람
		Button btnAlarm = (Button) findViewById(R.id.btn_subskill_alarm);
		
		Button conversationBtn = (Button)findViewById(R.id.subskill_conversation_btn);
		Button toiletBtn = (Button)findViewById(R.id.subskill_toilet_btn);
		Button subwayBtn = (Button)findViewById(R.id.subskill_subway_btn);
		
		toiletBtn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				v.startAnimation(loadAnimation);
				startActivity(new Intent(getBaseContext(), ToiletSearch.class));
			}
		});
		
		// 알람 이벤트
		btnAlarm.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				v.startAnimation(loadAnimation);
				startActivity(new Intent(getBaseContext(), Alarm.class));
			}
		});
		
		// 공항지도 버튼 이벤트
		btnAriport.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				v.startAnimation(loadAnimation);
				startActivity(new Intent(getBaseContext(), AirportGuideMain.class));
			}
		});
		
		// 긴급전화 버튼 이벤트
		btnTel.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				v.startAnimation(loadAnimation);
				startActivity(new Intent(getBaseContext(), Call.class));
			}
		});
		
		conversationBtn.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				v.startAnimation(loadAnimation);
				startActivity(new Intent(getBaseContext(), SubskillConversation.class));
			}
		});
		
		subwayBtn.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				v.startAnimation(loadAnimation);
				startActivity(new Intent(getBaseContext(), SubwaySearchMap.class));
			}
		});
		
	}
	
	private boolean isFinising = false;
    @Override
    public void onBackPressed() {
    	if(isFinising){
    		moveTaskToBack(true);
    		android.os.Process.killProcess(android.os.Process.myPid());
    	}
    	Toast.makeText(this, TranslateService.translateRepository("다시 한번 눌러 종료하세요"), 1).show();
    	Thread timeWorker = new Thread(new Runnable() {			
			@Override
			public void run() {
				isFinising = true;
				try {
					TimeUnit.SECONDS.sleep(2);
					isFinising = false;
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		});
    	timeWorker.start();
    }
	

}
